package com.cloudbroker.openapi.manage.controller;

import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.admin.back.CommentQueryResult;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.comment.back.CommentSaveBack;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.comment.back.CommentSearchResult;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.comment.back.CommentUpvoteResult;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.comment.vo.*;
import com.cloudbroker.bcs.platform.ltb.bizapi.t2service.social.CommentT2BizService;
import com.cloudbroker.bcs.platform.ltb.common.ext.annotation.SaveLog;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.cloudbroker.bcs.platform.ltb.common.util.RequestUtil.getSingleParameterMapForBody;

/**
 * Created by zhaosh19213 on 2016/7/17.
 */
@Controller
public class CommentController {

    @Resource
    private CommentT2BizService commentT2BizService;

    @ResponseBody
    @RequestMapping("/msg_comment_add")
    @SaveLog(remark = "评论提交")
    public CommentSaveBack CommentAdd(HttpServletRequest request, String jsonpcallback){
        CommentAddForm form = getSingleParameterMapForBody(request , CommentAddForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcSaveComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_reply")
    @SaveLog(remark = "评论回复")
    public CommentSaveBack CommentReply(HttpServletRequest request, String jsonpcallback) {
        CommentReplyForm form = getSingleParameterMapForBody(request, CommentReplyForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcReplyComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_mod")
    @SaveLog(remark = "评论修改")
    public CommentSaveBack CommentUpdate(HttpServletRequest request, String jsonpcallback) {
        CommentUpdateForm form = getSingleParameterMapForBody(request, CommentUpdateForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcUpdateComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_del")
    @SaveLog(remark = "评论屏蔽")
    public CommentSaveBack CommentClose(HttpServletRequest request, String jsonpcallback) {
        CommentStatusForm form = getSingleParameterMapForBody(request, CommentStatusForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcCloseComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_top")
    @SaveLog(remark = "评论置顶")
    public CommentSaveBack CommentTop(HttpServletRequest request, String jsonpcallback) {
        CommentTopForm form = getSingleParameterMapForBody(request, CommentTopForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.fucTopComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_qry")
    @SaveLog(remark = "评论")
    public CommentQueryResult queryCommentByTarget(HttpServletRequest request, String jsonpcallback) {
        CommentTargetForm form = getSingleParameterMapForBody(request, CommentTargetForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.fucQueryCommentByTarget(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_search")
    @SaveLog(remark = "评论搜索投顾")
    public CommentSearchResult queryCommentBy(HttpServletRequest request, String jsonpcallback) {
        CommentSearchForm form = getSingleParameterMapForBody(request, CommentSearchForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcSearchComment(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("msg_comment_upvote")
    @SaveLog(remark = "评论搜索投顾")
    public CommentUpvoteResult upvoteComment(HttpServletRequest request, String jsonpcallback) {
        CommentUpvoteForm form = getSingleParameterMapForBody(request, CommentUpvoteForm.class);
        return VOUtil.setJsonpResult(commentT2BizService.funcUpvoteComment(form), jsonpcallback);
    }
}
